<!-- 自定义标准图表 设置百分百宽度 通过平台组件来适配尺寸 可以替换数据以及设置高级属性自定义扩展 详细查看组件示例.txt
  注:如需设置图片存放文件夹名称需应与当前文件名一致(1并在aircim.webpack.build.component.config.js配置需要打包的文件 2.npm run lib_c 执行打包命令  最后的组件会打包在components/grids中)-->
<template>
  <div class="scale-box" :id="dynamicIdName()">
    <div
      class="service-situation-box animate__animated"
      :class="dynamicClassName"
      style="width: 460px;height: 921px;"
      :id="dynamicChildName()"
    >
      <h1 class="h1_title">
        <span>服务评价</span>
      </h1>
      <h2 class="h2_title">
        <span>评价渠道分布</span>
        <p class="h2_tab">
          <span :class="{'active':activeIndex==0}" @click="activeIndex = 0">线上渠道</span>
          <span :class="{'active':activeIndex==1}" @click="activeIndex = 1">线下渠道</span>
        </p>
      </h2>
      <div class="Bar-panel">
        <BarHorizontal :list="barList[activeIndex]"></BarHorizontal>
      </div>
      <h2 class="h2_title"><span>无评价办件</span></h2>
      <div class="assess-panel">
        <div>无评价办件</div>
        <div>
          <span><em>8346</em>件</span>
          <span><em>83.46</em>%</span>
        </div>
      </div>
      <div class="common-table" style="margin-bottom: 28px">
        <p class="table-name">
          <span class="table-index">排名</span>
          <span class="table-flex">部门名称</span>
          <span class="table-1-4">无评价办件</span>
          <span class="table-1-4">占比</span>
        </p>
        <TableScroll :container-height="120" :speed="10">
          <ul class="table-bd">
            <li class="table-bd-item" v-for="(item,index) in 3" :key="index" >
              <span class="table-index">NO.{{index+1}}</span>
              <span class="table-flex">部门名称字段内容</span>
              <div class="table-1-4">
                <p class="num"><em>2340</em>件</p>
              </div>
              <span class="table-1-4">
                  <p class="num"><em>2340</em>%</p>
                </span>
            </li>
          </ul>
        </TableScroll>
      </div>
      <h2 class="h2_title"><span>满意办件分布</span></h2>
      <div class="pie-chart" style="height: 166px;position: relative;margin-top: 36px;">
        <PieChart :echartdata="pieData" ></PieChart>
      </div>
    </div>
  </div>
</template>
<script>
//引入封装方法
import encapsulation from "../../utils/aircimGird";
import PieChart from "../elements/CustomPieChart.vue";
import TableScroll from "./TableScroll.vue";
import BarHorizontal from "./BarHorizontal.vue";
export default {
  //混入封装方法
  mixins: [encapsulation],
  components: {
    BarHorizontal,
    TableScroll,
    PieChart,
  },
  data() {
    return {
      resizeObserver: null,
      //动态Id
      timestamp: null,
      activeIndex:0,
      pieData:[
            {
              color:'#00D2DF',
              name:'非常满意',
              value:340,
            },
            {
              color:'#B994FF',
              name:'满意',
              value:230,
            },
            {
              color:'#85B9FF',
              name:'基本满意',
              value:340,
            },
            {
              color:'#49EEBD',
              name:'不满意',
              value:234,
            },
            {
              color:'#F2B073',
              name:'非常不满意',
              value:2340,
            },
          ],
      barList:[
        [
          {
            name:'此处为事项名称字段',
            num:'90.12',
            num_unit:'个',
            value:'90.12',
            unit:'%',
          },
          {
            name:'部门2',
            num:'90',
            num_unit:'个',
            value:'50',
            unit:'%'
          },
          {
            name:'部门3',
            num:'90',
            num_unit:'个',
            value:'20.1',
            unit:'%'
          },
        ],
        [
          {
            name:'123此处为事项名称字段',
            num:'90.12',
            num_unit:'个',
            value:'80.12',
            unit:'%',
          },
          {
            name:'123部门2',
            num:'40',
            num_unit:'个',
            value:'52.10',
            unit:'%'
          },
          {
            name:'123部门3',
            num:'920',
            num_unit:'个',
            value:'40.1',
            unit:'%'
          },
        ]
      ]
    };
  },
  mounted() {
    this.timestamp = new Date().getTime();
    this.$nextTick(() => {
      // 监听盒子变化
      this.listenChangeFn();
    });
  },
  methods: {
    //监听外部盒子的大小 然后对数据井行缩放
    scaleFn() {
      const parentBox = document.getElementById(`dynamic-${this.timestamp}`);
      const childBox = document.getElementById(
        `dynamicChild-${this.timestamp}`
      );
      const parentWidth = parentBox.offsetWidth;
      const parentHeight = parentBox.offsetHeight;
      const childWidth = childBox.offsetWidth;
      const childHeight = childBox.offsetHeight;
      let scaleX, scaleY;
      if (parentWidth < childWidth || parentHeight < childHeight) {
        const scaleBasedOnWidth = parentWidth / childWidth;
        const scaleBasedOnHeight = parentHeight / childHeight;
        scaleX = scaleBasedOnWidth;
        scaleY = scaleBasedOnHeight;
      } else {
        scaleX = parentWidth / childWidth;
        scaleY = parentHeight / childHeight;
      }
      childBox.style.transform = `scale(${scaleX}, ${scaleY})`;
    },
    // 监听盒子变化
    listenChangeFn() {
      let that = this;
      const element = document.getElementById(`dynamic-${this.timestamp}`);
      // console.log(element, "element");
      if (element) {
        new ResizeObserver(() => {
          // 处理元素大小变化的逻辑
          that.scaleFn();
        }).observe(element);
      }
    },
    // 绑定动画样式 animate__flash
    bindAnimationFn(animateName) {
      if (animateName != null) {
        this.dynamicClassName = animateName;
      }
    },
    //定义唯一ID名
    dynamicIdName() {
      return `dynamic-${this.timestamp}`;
    },
    //定义唯一ID名
    dynamicChildName() {
      return `dynamicChild-${this.timestamp}`;
    },
  },
  // 销毁监听
  beforeDestroy() {
    // 组件销毁前停止监听
    if (this.resizeObserver) {
      this.resizeObserver.disconnect();
    }
    if (this.requestTime != null) {
      clearInterval(this.requestTime);
    }
  },
};
</script>
<style lang="scss" scoped>
@import "../../static/assets/common.scss";
</style>
<style lang="scss" scoped>
.scale-box {
  width: 100%;
  height: 100%;
}

.service-situation-box {
  position: absolute;
  padding: 0 20px;
  box-sizing: border-box;
  overflow: hidden;
  transform-origin: left top;
  background-image: url(../../../thumbnail/backImg/new-border-green.png);
  background-size: 100% 100%;
  background-repeat: no-repeat;
  color: #fff;
}
.table-index{
  font-family: D-DIN;
  font-size: 16px;
  font-weight: 700;
}

.table-bd-item{
  &:nth-child(1) .table-index{
    background: linear-gradient(180deg, #FFF 0%, #FF2942 100%);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
  }
  &:nth-child(2) .table-index{
    background: linear-gradient(180deg, #FFF 22.6%, #D36B1F 100%);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
  }
  &:nth-child(3) .table-index{
    background: linear-gradient(180deg, #FFF 22.6%, #0085FF 100%);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
  }
}
.Bar-panel{
  margin: 13px 0;
}
.assess-panel{
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 24px 0 28px 0;
  width: 422px;
  height: 66px;
  background: url(../../static/assets/AssessService/panel_bg.png) no-repeat center center;
  background-size: cover;
  padding-left: 95px;
  div{
    display: flex;
    gap: 22px;
    color: #FFF;
    font-family: "Source Han Sans CN";
    font-size: 16px;
    font-weight: 500;
  }
  span {
    color: #96BEE0;
    font-family: "Source Han Sans CN";
    font-size: 14px;
    font-weight: 400;
    em{
      margin-right: 4px;
      color: #0FF;
      text-align: center;
      font-family: D-DIN;
      font-size: 24px;
      font-weight: 700;
    }
  }
}

</style>
